﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using System.Collections.Generic;

/// <summary>
/// PageBase 的摘要说明
/// </summary>
public class PageBase:Page
{
	public PageBase()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    /// <summary>
    /// 注册脚本
    /// </summary>
    /// <param name="msg">脚本</param>
    public void RegisterScript(string script)
    {
        StringBuilder str = new StringBuilder();
        str.Append("<script type=\"text/javascript\">");
        str.Append(script);
        str.Append("</script>");
        this.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), str.ToString(), false);
    }
    /// <summary>
    /// 脚本对话框
    /// </summary>
    /// <param name="msg">信息</param>
    public void Alert(string msg)
    {
        StringBuilder str = new StringBuilder();
        str.Append("<script type=\"text/javascript\">alert(\"");
        str.Append(msg);
        str.Append("\");</script>");
        this.ClientScript.RegisterStartupScript(this.GetType(),Guid.NewGuid().ToString(),str.ToString());
    }
    /// <summary>
    /// 脚本对话框
    /// </summary>
    /// <param name="msg">信息</param>
    public void AlertAndClose(string msg)
    {
        StringBuilder str = new StringBuilder();
        str.Append("<script type=\"text/javascript\">alert(\"");
        str.Append(msg);
        str.Append("\");window.opener=null;window.open('','_self');window.close();</script>");
        this.ClientScript.RegisterStartupScript(this.GetType(),Guid.NewGuid().ToString(),str.ToString());
    }
    /// <summary>
    /// 脚本对话框
    /// </summary>
    /// <param name="msg">信息</param>
    /// <param name="url">跳转页</param>
    public void AlertAndRedirect(string msg, string url)
    {
        StringBuilder str = new StringBuilder();
        str.Append("<script type=\"text/javascript\">alert(\"");
        str.Append(msg);
        str.Append("\");window.location.href='");
        str.Append(url);
        str.Append("';</script>");
        this.ClientScript.RegisterStartupScript(this.GetType(),Guid.NewGuid().ToString(),str.ToString(),false);
    }
    /// <summary>
    /// 获取GET方式发送的参数
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public string GetQueryString(string name)
    {
        return Request.QueryString[name] ?? string.Empty;
    }

    /// <summary>
    /// 获取POST方式发送的参数
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public string GetParams(string name)
    {
        return Request.Params[name] ?? string.Empty;
    }
    /// <summary>
    /// 替换特殊字符
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public string GetReplaceName(string name)
    {
        name = name.Replace("'", "");
        name = name.Replace("(", "（");
        name = name.Replace(")", "）");
        name = name.Replace("\\", ".");
        name = name.Replace("\"", "。");
        name = name.Replace("孒", "子");
        name = name.Replace("/", "");
        name = name.Replace("、", "");
        name = name.Replace("{", ".");
        name = name.Replace("}", ".");
        name = name.Replace(",", "，");
        name = name.Replace("<", "");
        name = name.Replace(">", "");
        return name;
    }
}
